import request from '@/utils/request'

// 登录
export function userLogin(username, password, code) {
    return request({
        url: '/login',
        method: 'post',
        headers: {
            isToken: false
          },
        data: {'username': username, 'password': password, 'code': code}
    })
}

export function userRegister(username,nickName,email,password,code) {
    return request({
        url: '/user/register',
        method: 'post',
        headers: {
            isToken :false
        },
        data: {"username":username,"nickName":nickName,"email":email,"password":password,'code': code}
    })
}


export function logout() {
    return request({
        url: '/logout',
        method: 'post'
    })
}

export function getUserInfo(userId) {
    return request ({
        url: '/user/userInfo',
        method: 'get',
        params: {"userId":userId}
    })
}

//增加积分
export function saveuserexp(userexp) {
    return request({
        url: '/user/userExp',
        method: 'put',
        data: userexp
    })
}
//兑换积分
export function exchangevip(vipExchangedata) {
    return request({
        url: '/user/uservipExchange',
        method: 'put',
        data: vipExchangedata
    })
}

export function savaUserInfo(userinfo) {
    return request({
        url: '/user/userInfo',
        method: 'put',
        data: userinfo
    })
}
//个人中心修改密码
export function updatePassword(id,password) {
    return request({
        url: '/user/updatePassword',
        method: 'put',
        headers:{
            isToken:false
        },
        data: {'id':id,'password':password}
    })
}


//找回密码
export async function handleForgotPassword(userName, email, password,code) {
   return request({
    url:'/user/handpassword',
    method:'post',
    headers:{
        isToken:false
    },
    data:{'userName':userName,'email':email,'password':password,'code':code,}
   })
}
export function getUserByUsername(username) {
    return request({
      url: "/user/getUserByUsername",
      method: "get",
      params: { username },
    })
}